<template>
	<view class="container-bottom-btns">
		<view class="form">
			<view class="form-column-item">
				<view class="label">原密码</view>
				<view class="content">
					<input v-model="form.originalPassword" placeholder-class="placeholder-input" type="password" placeholder="请输入原密码" />
				</view>
			</view>
			<view class="form-column-item">
				<view class="label">新密码</view>
				<view class="content">
					<input v-model="form.password" placeholder-class="placeholder-input" type="password" placeholder="请输入新密码" />
				</view>
			</view>
			<view class="form-column-item">
				<view class="label">确认密码</view>
				<view class="content">
					<input v-model="form.verifyPassword" placeholder-class="placeholder-input" type="password" placeholder="请输入确认密码" />
				</view>
			</view>
			
		</view>
		
		<view class="bottom-btn-wrapper">
			<SubmitBtn text="提交" :customStyle="{width: '690rpx'}" @tap="submit"></SubmitBtn>
		</view>

	</view>
</template>

<script>
	import { toast } from '../../utils/uni-api';
import { updatePassword } from '@/api/user.js'
	import validate from '@/utils/validate.js'
	export default {
		data() {
			return {
				form:{
					type: 2, // 类型(1-设置密码 2-修改密码)
					originalPassword: '', 
					password: '',
					verifyPassword: ''
				}
			};
		},
		methods: {
			submit(){
				if(!validate.isNotEmpty(this.form.originalPassword, '原密码')) return 
				if(!validate.isNotEmpty(this.form.password, '新密码')) return 
				if(!validate.isNotEmpty(this.form.verifyPassword, '确认密码')) return 
				
				updatePassword(this.form).then(res => {
					toast('修改成功')
					setTimeout(() => {
						uni.navigateBack({delta:1})
					}, 800)
				})
			}
		}
	}
</script>

<style lang="scss">
	
</style>